package com.hbzhit.modules.sys.controller;

import com.alibaba.fastjson.JSONArray;
import com.hbzhit.common.utils.ConfigConstant;
import com.hbzhit.common.utils.R;
import com.hbzhit.modules.sys.entity.SysBannerEntity;
import com.hbzhit.modules.sys.service.SysConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * LOGO配置
 *
 * @author DING
 * @date 2019-07-09 19:07:15
 */
@Api(tags = {"轮播图配置"})
@RestController
@RequestMapping("sys/banner")
public class SysBannerController {
    @Autowired
    private SysConfigService sysConfigService;

    /**
     * 获取配置
     */
    @ApiOperation(value = "列表")
    @GetMapping("/list")
    public R<List<SysBannerEntity>> list(){
        String bannerStr = sysConfigService.getValue(ConfigConstant.BANNER_CONFIG_KEY);
        List<SysBannerEntity> bannerList = JSONArray.parseArray(bannerStr, SysBannerEntity.class);

        return R.ok(bannerList);
    }

    /**
     * 保存配置
     */
    @ApiOperation(value = "保存配置")
    @PostMapping("/save")
    public R save(@RequestBody List<SysBannerEntity> banner){
        sysConfigService.updateValueByKey(ConfigConstant.BANNER_CONFIG_KEY, JSONArray.toJSONString(banner));

        return R.ok();
    }

}
